package queue;

import java.util.Random;

public class QueueTest {

    public static void main(String[] args) {
        LinkedListQueue<Integer> linkedListQueue = new LinkedListQueue<Integer>();
        for (int i = 0; i < 10; i++) {
            linkedListQueue.enqueue(i);
            System.out.println(linkedListQueue);

            if (i % 3 == 2) {
                linkedListQueue.dequeue();
                System.out.println(linkedListQueue);
            }
        }


        System.out.println();

        ArrayQueue<Integer> arrayQueue = new ArrayQueue<Integer>();
        for (int i = 0; i < 10; i++) {
            arrayQueue.enqueue(i);
            System.out.println(arrayQueue);

            if (i % 3 == 2) {
                arrayQueue.dequeue();
                System.out.println(arrayQueue);
            }
        }


        System.out.println();

        LoopQueue<Integer> loopQueue = new LoopQueue<Integer>();
        for (int i = 0; i < 10; i++) {
            loopQueue.enqueue(i);
            System.out.println(loopQueue);

            if (i % 3 == 2) {
                loopQueue.dequeue();
                System.out.println(loopQueue);
            }
        }

        System.out.println();

        int opCount = 100000;

        ArrayQueue<Integer> aQueue = new ArrayQueue<Integer>();
        double aTime = test(aQueue, opCount);
        System.out.println("ArrayQueue, time: " + aTime + "s");

        System.out.println();

        LoopQueue<Integer> lQueue = new LoopQueue<Integer>();
        double lTime = test(lQueue, opCount);
        System.out.println("LoopQueue, time: " + lTime + "s");

        System.out.println();

        LinkedListQueue<Integer> linkedQueue = new LinkedListQueue<Integer>();
        double linkedListTime = test(linkedQueue, opCount);
        System.out.println("LinkedListQueue, time: " + linkedListTime + "s");

    }

    private static double test(Queue<Integer> queue, int opCount) {
        long startTime = System.nanoTime();
        Random random = new Random();
        for (int i = 0; i < opCount; i++) {
            queue.enqueue(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount; i++) {
            queue.dequeue();
        }
        long endTime = System.nanoTime();
        return (endTime - startTime) / 1000000000.0;
    }

}
